package com.centaur0.io;

import java.io.IOException;

import javax.servlet.jsp.JspWriter;

public class JspWriterImpl extends JspWriter {

	StringBuilder buffer = new StringBuilder();

	public JspWriterImpl(int bufferSize, boolean autoflush){
		super(bufferSize, autoflush);
	}
	
	public JspWriterImpl(){
		this(1024, false);
	}
	
	@Override
	public void newLine() throws IOException {
		buffer.append("\n");
	}

	@Override
	public void print(boolean b) throws IOException {
		buffer.append(b);
	}

	@Override
	public void print(char c) throws IOException {
		buffer.append(c);
	}

	@Override
	public void print(int i) throws IOException {
		buffer.append(i);
	}

	@Override
	public void print(long l) throws IOException {
		buffer.append(l);
	}

	@Override
	public void print(float f) throws IOException {
		buffer.append(f);
	}

	@Override
	public void print(double d) throws IOException {
		buffer.append(d);
	}

	@Override
	public void print(char[] s) throws IOException {
		buffer.append(s);
	}

	@Override
	public void print(String s) throws IOException {
		buffer.append(s);
	}

	@Override
	public void print(Object obj) throws IOException {
		buffer.append(obj);
	}

	@Override
	public void println() throws IOException {
		buffer.append("\n");
	}

	@Override
	public void println(boolean x) throws IOException {
		this.print(x);
		this.println();

	}

	@Override
	public void println(char x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(int x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(long x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(float x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(double x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(char[] x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(String x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void println(Object x) throws IOException {
		this.print(x);
		this.println();
	}

	@Override
	public void clear() throws IOException {
		buffer = new StringBuilder();
	}

	@Override
	public void clearBuffer() throws IOException {
		this.clear();
	}

	@Override
	public void flush() throws IOException {
		buffer.trimToSize();
	}

	@Override
	public void close() throws IOException {
		buffer = null;
	}

	@Override
	public int getRemaining() {
		return buffer.capacity() - buffer.length(); 
	}

	@Override
	public void write(char[] arg0, int arg1, int arg2) throws IOException {
		buffer.append(new String(arg0, arg1, arg2));
	}
	
	@Override
	public String toString() {
		return buffer == null? "": buffer.toString();
	}

}
